<?php
/**
 * Created by Silent Night.
 * Author: Silent Night
 * email: silentwolf_wp@163.com
 * Date: 2017/9/28
 * Time: 9:19
 */

namespace app\admin\controller;

use think\Controller;

class Tip extends Controller
{
    private $_model;
    private $title_field = [

    ];
    public $pagesize = 10;

    public function _initialize()
    {
        (new \app\admin\behavior\CheckPermissions())->run();//增加权限控制
        $this->_model = new \app\admin\model\Tip();
        $this->assign('LoginUserInfo', $this->LoginUserInfo);
        //获取当前用户的权限信息
        $this->assign('ruleLists', $this->LoginUserInfo['CurrPower']);
    }
    
    
    public function deal()
    {
        $return = [];
        $id = trim(input("request.id"));//auth

        if (empty($id)) {
            $return = ['err' => 1, 'msg' => '操作失败'];
            return json($return);
        }

        $res = $this->_model->updateData(array('status' => 1), $id);

        if ($res || $res === 0) {
            $return = ['err' => 0, 'msg' => '操作成功'];
            return json($return);
        } else {
            $return = ['err' => 3, 'msg' => '操作失败'];
            return json($return);
        }
    }
    

   public function lists(){
       $ser_key = trim(input("request.ser_key"));//auth
       $ser_val = trim(input("request.ser_val"));//auth
   
       $ser_stats = trim(input("request.ser_stats"));//auth
       
       if ($ser_key && $ser_val) {
           $where[$ser_key] = array('like', '%' . $ser_val . '%');
       }
       
       if ($ser_stats == '0' || $ser_stats == '1') {
           $where['status'] = $ser_stats;
       }
   
       $lists = $this->_model->lists($where, $this->pagesize);
       foreach ($lists['data'] as $key=>$val){

           $lists['data'][$key]['ctime']=date("Y-m-d H:i:s",$val['ctime']);
           $tempInfo = $this->getNoteInfo($val['tid']);
           $lists['data'][$key]['noteTitle']="";

           if($tempInfo)
           {
               $lists['data'][$key]['noteTitle']=$tempInfo['content'];
           }
       }
       $lists['data'] = changeUidToUserinfoForLists($lists['data'], 'uid');
       $this->assign('lists', $lists);
       $this->assign('request', input("request."));
       return view('lists');
   }
   public function getNoteInfo($id)
   {
       $model = new \app\admin\model\Notes();
       return $model->getID($id);

   }
}